/**
 * encodeing: UTF-8
*/

#ifndef _ROOM_H
#define _ROOM_H
#pragma once

#include <stdio.h>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <thread>
#include <windows.h>
#include "sqlite3.h"

#include "DB.h"

#define SQL_LENGTH 1000
#define HIGH_WIND_TEMPRATURE 0.6
#define MID_WIND_TEMPRATURE 0.5
#define LOW_WIND_TEMPRATURE 0.4
//#define MAX_TEMPRATURE 30
//#define DEFAULT_TEMPRATURE 25
//#define MIN_TEMPRATURE 18
#define DEFAULT_MAX_T 999
#define TEMPRATURE_UPDATE_TIME 60000

/*
enum class IdentityR :int { CLIENT, RECEPTION, MANAGER, ADMIN };
enum class Type :int { QUERY, RESPONSE };
enum class QueryType :int {
    DETAIL, PAYMENT, DEFAULT, STATEMENT, CHANGEDEFAUL,
    ROOM, CHANGEROOM, AUTH, INSERT, ONOFF, WINDSTOP, WINDSTART };
enum class ResponseType :int { DETAIL, PAYMENT, DEFAULT, STATEMENT, ROOM, AUTH };
enum class FanSpeed :int { LOW = 1, MEDIUM, HIGH };
enum class RoomState :int { SERVING = 1, WAITING, POWEROFF, SLEEPING };
*/

/*
class DBFacade {
public:
    std::vector<Json::Value> to_schedule_list;
    Json::Value RoomQuery(Json::Value val);
    void RoomTemperature(std::vector<Json::Value> *ptr);
    void RoomScan(std::vector<Json::Value> &list);
    static void RoomScanTimer(LPVOID list);
    Json::Value RoomResponse(Json::Value val);
    
    double getRoomBill(int id);
};
*/

/*
class Room {
private:
    time_t _time;//current
    Type _type;//q or r
    IdentityR _source;
    IdentityR _destination;
    QueryType _queryType;
    ResponseType _responseType;
    int _roomId;
    RoomState _state;
    double _targetT;//from scheduler
    FanSpeed _targetW;//from scheduler
    double _nowT;//from db
    FanSpeed _nowW;//from db
    double _initT;
    double _fee;//from recordBean
    int _power;//from scheduler
public:
    Room(void);
    ~Room() = default;

    bool deleteInfo(Json::Value val);
    bool getInfo(Json::Value val, Json::Value &response);
    bool changeInfo(Json::Value val);
    bool changePower(Json::Value val);
    int editTemperature(void);
    std::string pack(Json::Value);

    time_t getTime(void);
    Type getType(void);
    IdentityR getSource(void);
    IdentityR getDestination(void);
    QueryType getQueryType(void);
    ResponseType getResponseType(void);
    int getRoomId(void);
    RoomState getRoomState(void);
    double getTargetT(void);
    FanSpeed getTargetW(void);
    double getCurrentT(void);
    FanSpeed getCurrentW(void);
    double getInitT(void);
    double getBill(void);
    int getPower(void);

    void setTime(time_t time);
    void setType(Type type);
    void setSource(IdentityR src);
    void setDestination(IdentityR des);
    void setQueryType(QueryType query);
    void setResponseType(ResponseType rsp);
    void setRoomId(int id);
    void setRoomState(RoomState state);
    void setTargetT(double t_temp);
    void setTargetW(FanSpeed t_wind);
    void setCurrentT(double c_temp);
    void setCurrentW(FanSpeed c_wind);
    void setInitT(double i_temp);
    void setBill(double bill);
    void setPower(int power);

    //change wind/temp/power
    //get info/bill

    //DBFacade receives a query, then initialize a room with it
    //with a DBFacade::function
    //roombean is a global unique one(?)
    //the room decide which bean-method to use with json::value
    //one Room::function to judge the query type and use the functions below
    //wind: setCurrentW, then setCurrentT and Update every 60 secs
    //temp: setCurrentT, then Update
    //power: same
    //info: Query, then return a json::value
    //bill: not decided
};

class RoomBean {
private:
    const char *dataPath = "RoomBean.db";
    sqlite3 *roomDatabase;
public:
    sqlite3_stmt *stmt = NULL;
    RoomBean();
    ~RoomBean();
    bool Insert(Room *room);
    bool Update(Room *room);
    bool Update_power(Room *room);
    bool Delete(Room *room);
    bool Query(Room *room);
    bool Query(std::vector<int> &roomlist);
};
*/
#endif